$(function () {
    $("#btn_login").click(function () {
        var user_name = document.getElementById("user_name");
        var password = document.getElementById("Password");
        var flag = 1;
        if (user_name.value == "") {
            alert("用户名不能为空!");
            flag = 0;
        }
        else {
            if (password.value == "") {
                alert("密码不能为空!");
                flag = 0;
            }
            if (flag == 1) {
                $.get(
                    "/LoginCheckServlet",
                    {user_name: user_name.value, password1: password.value},
                    function (data) {
                        var exit = data.exit;
                        if (exit == 0) {
                            alert("该用户名不存在");
                        }
                        else if(exit == 2){
                            alert("密码错误");
                        }
                        else {
                            alert("登陆成功，点击确认后前往用户页面");
                            window.location.href = "user.jsp?username=" + user_name.value;
                        }
                    }
                );
            }
        }
    });
});
